package com.dailyblue.project.estate.car.controller;

import com.dailyblue.project.estate.car.service.CarService;
import com.dailyblue.project.estate.commons.bean.Car;
import com.dailyblue.project.estate.commons.util.JsonResult;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/car")
public class CarController {
    @Resource
    private CarService carService;

    @PostMapping
    public JsonResult save(Car car) {
        return carService.addCar(car);
    }

    @GetMapping("/findOne/{id}")
    JsonResult findOne(@PathVariable("id") String id) {
        return carService.findOneCar(id);
    }

    @GetMapping("/all")
    JsonResult findAll(){
        return carService.findAllCars();
    }
    @DeleteMapping("/delete/{id}")
    JsonResult deleteOne(@PathVariable("id") String id){
        return carService.deleteCar(id);
    }

    @PutMapping("/update")
    JsonResult update(@RequestBody Car car){
        return carService.updateCar(car);
    }
}
